package com.techsoul.module.goods.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.module.goods.pojo.param.BrandCategoryRelSaveParam;
import com.techsoul.module.goods.pojo.param.BrandCategoryRelSearchParam;
import com.techsoul.module.goods.service.IBrandCategoryRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 品牌分类关系 Controller
 *
 * @author liuen
 * @date 2020-12-14
 */
@Api(tags = "品牌分类关系")
@RestController
@RequestMapping("/goods/brandCategoryRel")
public class BrandCategoryRelController {

    @Autowired
    private Result result;
    
    @Autowired
    private IBrandCategoryRelService service;

    @ApiOperation("新增")
    @PreAuthorize("hasAnyAuthority('goods:brandCategoryRel:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody BrandCategoryRelSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @PreAuthorize("hasAnyAuthority('goods:brandCategoryRel:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @PreAuthorize("hasAnyAuthority('goods:brandCategoryRel:update')")
    @PutMapping
    public Result update(@Valid @RequestBody BrandCategoryRelSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('goods:brandCategoryRel:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('goods:brandCategoryRel:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody BrandCategoryRelSearchParam params) {
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('goods:brandCategoryRel:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody BrandCategoryRelSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }

}
